package seismosurfer.gui.menu;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

import javax.help.CSH;
import javax.swing.JMenuItem;

import seismosurfer.gui.menuitem.SeismoAboutMenuItem;
import seismosurfer.http.HttpGateway;
import seismosurfer.util.ClientRegistry;

import com.bbn.openmap.gui.AbstractOpenMapMenu;

/**
 * HelpMenu creates menu items that invoke
 * web pages or the help window. Also, includes
 * SeismoAboutMenuItem.
 *
 */
public class HelpMenu extends AbstractOpenMapMenu implements ActionListener {
    
    private static final long serialVersionUID = -4055430012873027126L;

    private static String defaultText = "Help";

    private static int defaultMnemonic = 'H';

    private static final String MERCALLI = "Modified Mercalli Intensity Scale";

    private static final String CONTACT = "Contact us";

    private static final String GLOSSARY = "Earthquakes Glossary";

    private static final String mercalliURL = "help.jsp#mercalli";

    private static final String glossaryURL = "help.jsp#glossary";

    private static final String contactURL = "contact.jsp";

    public HelpMenu() {
        super();
        setText(defaultText);
        setMnemonic(defaultMnemonic);

        CSH.setHelpIDString(this, "d0e4");

        // Menu Items for the Help Menu
        JMenuItem helpMenuItem = new JMenuItem(defaultText, KeyEvent.VK_P);

        helpMenuItem.addActionListener(new CSH.DisplayHelpFromSource(
                ClientRegistry.getHelpBroker()));
        helpMenuItem.setActionCommand(defaultText);
        add(helpMenuItem);

        addMenuItem(MERCALLI, KeyEvent.VK_M);
        addMenuItem(GLOSSARY, KeyEvent.VK_G);

        addSeparator();

        addMenuItem(CONTACT, KeyEvent.VK_C);

        add(new SeismoAboutMenuItem());

    }

    protected void addMenuItem(String name, int key) {
        JMenuItem mi = new JMenuItem(name, key);
        mi.addActionListener(this);
        mi.setActionCommand(name);
        add(mi);
    }

    public void actionPerformed(ActionEvent e) {

        String name = e.getActionCommand();

        if (name.equals(defaultText)) {
            // HttpMessageBus.showInternalWebPage(helpPageURL);
        } else if (name.equals(CONTACT)) {
            HttpGateway.showInternalWebPage(contactURL);
        } else if (name.equals(MERCALLI)) {
            HttpGateway.showInternalWebPage(mercalliURL);
        } else if (name.equals(GLOSSARY)) {
            HttpGateway.showInternalWebPage(glossaryURL);
        }

    }

}
